//-------------------------------------------------------------------
//	Copyright (c) 2012-2014 Zhirnov Andrey
//	This file is part of the "UXGEN-ES" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#include "Scene2D/SceneManager.h"
#include "Scene2D/Objects/SceneObject.h"

namespace Engine
{
namespace Scene2D
{
	
/*
=================================================
	Draw
=================================================
*/
	void SceneManager::Draw ()
	{
		// TODO
		/*
		_renderQueue.Draw( ERenderLayer::BACKGROUND );
		_renderQueue.Draw( ERenderLayer::OPAQUE );
		_renderQueue.Draw( ERenderLayer::TRANSLUCENT );
		_renderQueue.Draw( ERenderLayer::FOREGROUND );*/
	}

/*
=================================================
	Attach
=================================================
*/
	void SceneManager::Attach (SceneObject *obj)
	{
		typedef SceneObjMsg		SO;

		CHECK_ERR( obj != null, );

		obj->ProcessMessage( SO( SO::ATTACH_TO_SCENE, SO::AttachToScene( this, obj ) ) );

		_objects.PushBack( obj );
	}
	
/*
=================================================
	Detach
=================================================
*/
	void SceneManager::Detach (SceneObject *obj)
	{
		typedef SceneObjMsg		SO;

		CHECK_ERR( obj != null, );

		obj->ProcessMessage( SO( SO::DETACH_FROM_SCENE, SO::AttachToScene( this, obj ) ) );

		_objects.FindAndErase( obj );
	}
	
/*
=================================================
	DetachAll
=================================================
*/
	void SceneManager::DetachAll ()
	{
		typedef SceneObjMsg		SO;

		FOR( i, _objects )
		{
			_objects[i]->ProcessMessage( SO( SO::DETACH_FROM_SCENE, SO::AttachToScene( this, _objects[i] ) ) );
		}
		_objects.ClearMem();
	}
	
/*
=================================================
	_SendMessageToAll
=================================================
*/
	void SceneManager::_SendMessageToAll (const SceneObjMsg &msg)
	{
		FOR( i, _objects )
		{
			_objects[i]->ProcessMessage( msg );
		}
	}
	
/*
=================================================
	Load
=================================================
*/
	bool SceneManager::Load (uni_c_string filename)
	{
		return false;
	}


}	// Scene2D
}	// Engine